﻿using System;
using System.Windows.Forms;
using Benchmark.Entitie;
using DDotNet.DataFactory;

namespace Benchmark
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonInserir_Click(object sender, EventArgs e)
        {
            CRUDFactory factory = new CRUDFactory();
            int total = (int) this.numericUpDownQtdInserir.Value;
            DateTime startTime = DateTime.Now;

            using (factory)
            {
                for (int i = 1; i < total + 1; i++)
                {
                    BenchmarkItem item = new BenchmarkItem();

                    item.BitField = true;
                    item.DateTimeField = DateTime.Now;
                    item.DecimalField = (decimal) 15.6;
                    item.FloatField = 55996.6922569f;
                    item.MemoField = "123456789.+-*/qwertyuiop´[]~çlkjhgfdsazxcvbnbnm,.;/+_)(*&¨%$#@!";
                    item.MoneyField = (decimal) 12345678959.6653397;
                    item.NumberField = total;
                    item.SmallField = 1;
                    item.TextField = item.MemoField + item.MemoField;
                    factory.Update(item);
                    
                    if (i % 99 == 0)
                    {
                        detalhesInclusao.Text = "Inseridos " + i + " de " + total + " (" + (((decimal) i / (decimal) total) * 100) + ") %";
                        Application.DoEvents();
                    }
                }
            }
            
            DateTime endTime = DateTime.Now;
            TimeSpan totalTime = endTime.Subtract(startTime);
            detalhesInclusao.Text = string.Format("Inseridos {0} registros em {1} segundos. Tempo indivídual de {2} segundos/registro", total, totalTime.TotalSeconds, totalTime.TotalSeconds / total);
        }
    }
}